﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.JournalLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem.Issues;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class JournalLogEntry : LogEntry
  {
    [SaveableField(10)]
    public readonly TextObject Title;
    [SaveableField(20)]
    public readonly Hero RelatedHero;
    [SaveableField(30)]
    public readonly Hero Antagonist;
    [SaveableField(40)]
    private List<JournalLog> _entries;
    [SaveableField(50)]
    public readonly bool IsSpecial;
    [SaveableField(61)]
    private IssueBase.IssueUpdateDetails _lastIssueStatus;
    [SaveableField(70)]
    private QuestBase.QuestCompleteDetails _questCompletionDetail;
    [SaveableField(80)]
    private readonly string[] _relatedObjectIds;

    internal static void AutoGeneratedStaticCollectObjectsJournalLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Title);
      collectedObjects.Add((object) this.RelatedHero);
      collectedObjects.Add((object) this.Antagonist);
      collectedObjects.Add((object) this._entries);
      collectedObjects.Add((object) this._relatedObjectIds);
    }

    internal static object AutoGeneratedGetMemberValueTitle(object o)
    {
      return (object) ((JournalLogEntry) o).Title;
    }

    internal static object AutoGeneratedGetMemberValueRelatedHero(object o)
    {
      return (object) ((JournalLogEntry) o).RelatedHero;
    }

    internal static object AutoGeneratedGetMemberValueAntagonist(object o)
    {
      return (object) ((JournalLogEntry) o).Antagonist;
    }

    internal static object AutoGeneratedGetMemberValueIsSpecial(object o)
    {
      return (object) ((JournalLogEntry) o).IsSpecial;
    }

    internal static object AutoGeneratedGetMemberValue_entries(object o)
    {
      return (object) ((JournalLogEntry) o)._entries;
    }

    internal static object AutoGeneratedGetMemberValue_lastIssueStatus(object o)
    {
      return (object) ((JournalLogEntry) o)._lastIssueStatus;
    }

    internal static object AutoGeneratedGetMemberValue_questCompletionDetail(object o)
    {
      return (object) ((JournalLogEntry) o)._questCompletionDetail;
    }

    internal static object AutoGeneratedGetMemberValue_relatedObjectIds(object o)
    {
      return (object) ((JournalLogEntry) o)._relatedObjectIds;
    }

    public override CampaignTime KeepInHistoryTime
    {
      get => !this.IsSpecial ? CampaignTime.Years(1f) : CampaignTime.Years(10000f);
    }

    public JournalLogEntry(
      TextObject title,
      Hero relatedHero,
      Hero antagonist,
      bool isSpecial,
      params MBObjectBase[] relatedObjects)
    {
      this.Title = title;
      this.RelatedHero = relatedHero;
      this.Antagonist = antagonist;
      this._lastIssueStatus = IssueBase.IssueUpdateDetails.None;
      this._questCompletionDetail = QuestBase.QuestCompleteDetails.Invalid;
      this.IsSpecial = isSpecial;
      this._relatedObjectIds = new string[relatedObjects.Length];
      for (int index = 0; index < relatedObjects.Length; ++index)
        this._relatedObjectIds[index] = relatedObjects[index].StringId;
    }

    public bool IsRelatedTo(MBObjectBase obj)
    {
      return ((IEnumerable<string>) this._relatedObjectIds).Contains<string>(obj.StringId);
    }

    public IEnumerable<JournalLog> GetEntries()
    {
      foreach (JournalLog entry in this._entries)
        yield return entry;
    }

    public void Update(MBReadOnlyList<JournalLog> entries, IssueBase.IssueUpdateDetails issueStatus = IssueBase.IssueUpdateDetails.None)
    {
      this._entries = entries.ToList<JournalLog>();
      if (issueStatus == IssueBase.IssueUpdateDetails.None)
        return;
      this._lastIssueStatus = issueStatus;
    }

    public void Update(
      MBReadOnlyList<JournalLog> entries,
      QuestBase.QuestCompleteDetails questCompletionDetail)
    {
      this._entries = entries.ToList<JournalLog>();
      this._questCompletionDetail = questCompletionDetail;
    }

    public bool IsEndedUnsuccessfully()
    {
      return this._lastIssueStatus != IssueBase.IssueUpdateDetails.None ? this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueCancel || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueFail || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueTimedOut || this._lastIssueStatus == IssueBase.IssueUpdateDetails.SentTroopsFailedQuest || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueFinishedWithBetrayal : this._questCompletionDetail == QuestBase.QuestCompleteDetails.Cancel || this._questCompletionDetail == QuestBase.QuestCompleteDetails.Fail || this._questCompletionDetail == QuestBase.QuestCompleteDetails.FailWithBetrayal || this._questCompletionDetail == QuestBase.QuestCompleteDetails.Timeout;
    }

    public bool IsEnded()
    {
      if (this._lastIssueStatus == IssueBase.IssueUpdateDetails.None)
        return this._questCompletionDetail != 0;
      return this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueCancel || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueFail || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueTimedOut || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueFinishedWithBetrayal || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueFinishedByAILord || this._lastIssueStatus == IssueBase.IssueUpdateDetails.SentTroopsFinishedQuest || this._lastIssueStatus == IssueBase.IssueUpdateDetails.SentTroopsFailedQuest || this._lastIssueStatus == IssueBase.IssueUpdateDetails.IssueFinishedWithSuccess;
    }

    public override string ToString() => "Quest status change";
  }
}
